// Learn TypeScript:
//  - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html

import findPaht from "./findPaht";

const {ccclass, property} = cc._decorator;

@ccclass
export default class nodeGrid extends cc.Component {

    @property(cc.Label)
    label: cc.Label = null;

    @property
    text: string = 'hello';

    dataGrid: DataGrid = null;
    findPaht: findPaht;

    // LIFE-CYCLE CALLBACKS:

    onLoad () {
        this.node.on(cc.Node.EventType.TOUCH_START, this.onTouch, this);
    }

    start () {

    }

    updateGridColor() {
        let dataGrid = this.dataGrid;
        if(!dataGrid){ return;}
        switch(dataGrid.type){
            case GirdType.Normal: //正常状态
                this.node.color = new cc.Color(255,255,255,255); //白色
                break;
            case GirdType.Wall:   //代表墙
                this.node.color = new cc.Color(0,0,0,255);       //黑色
                break;
            case GirdType.Road:   //代表走过的路
                this.node.color = new cc.Color(0,255,0,255);     //绿色
                break;
            default:              //代表起始点和结束点
                this.node.color = new cc.Color(255,255,0,255);   //黄色
                break;
        }
    }

    onTouch(touch: cc.Event) {
        this.findPaht.onTouch(this);
    }

    onDestroy(){
        this.node.off(cc.Node.EventType.TOUCH_START, this.onTouch, this);
    }
}  



//每个格子具备的相关数据
export class DataGrid {
    constructor(type, i, j){
        this.type = type;
        this.i = i;
        this.j = j;
    }
    type: GirdType;
    i: number;
    j: number;

    inOpen: boolean = false;    //记录是否加入到存储结构中
    inClose: boolean = false;   //
}

//枚举出路径格子的状态
export enum GirdType{
    Normal,
    Wall,
    Start,
    End,
    Road,
}